/*
 * sk_util.c
 *
 *  Created on: Feb 28, 2011
 *      Author: asish
 */

#include "sk_util.h"

IplImage *
SK_SmoothImage(IplImage *in, int l_smoothType, int param1, int param2, double param3, double param4)
{
	CvRect l_roiRect;
	IplImage* out = cvCreateImage(
			cvSize( in->width,in->height),
					IPL_DEPTH_8U,
					3);
	assert(NULL != in);
	l_roiRect = cvGetImageROI(in);
    cvSetImageROI(out,l_roiRect);
	cvSmooth(in, out, l_smoothType, param1, param2, 0, 0);
	return (out);
}

IplImage* SK_DoCanny(
		IplImage* in,
		double lowThresh,
		double highThresh,
		double aperture)
{
	CvRect l_roiRect;
	if (in->nChannels != 1)
	{
		return NULL; //Canny only handles gray scale images
	}

	IplImage* out = cvCreateImage(
			cvSize( in->width,in->height),
					IPL_DEPTH_8U,
					1);
	l_roiRect = cvGetImageROI(in);
    cvSetImageROI(out,l_roiRect);
	cvCanny( in, out, lowThresh, highThresh, aperture );
	return( out );
};

IplImage* SK_DoSobel(
		IplImage* in,
		int xOrder,
		int yOrder,
		double aperture)
{
	CvRect l_roiRect;
	if (in->nChannels != 1)
	{
		return NULL; //Sobel only handles gray scale images
	}

	IplImage* out = cvCreateImage(
			cvSize( in->width,in->height),
					IPL_DEPTH_8U,
					1);
	l_roiRect = cvGetImageROI(in);
    cvSetImageROI(out,l_roiRect);
	cvSobel( in, out, xOrder, yOrder, aperture );
	return( out );
};


IplImage* SK_DoThreshold(
		IplImage* in,
		double threshold,
		double maxVal,
		double type)
{
	CvRect l_roiRect;
	IplImage* out = cvCreateImage(
			cvSize( in->width,in->height),
					IPL_DEPTH_8U,
					1);
	l_roiRect = cvGetImageROI(in);
    cvSetImageROI(out,l_roiRect);

	cvThreshold( in, out, threshold, maxVal, type );
	return( out );
};
